package io.github.talelin.latticy.controller.zty;

import io.github.talelin.core.annotation.LoginRequired;
import io.github.talelin.latticy.pojo.DispatchList;
import io.github.talelin.latticy.pojo.OutputList;
import io.github.talelin.latticy.service.DispatchListService;
import io.github.talelin.latticy.service.OutputListService;
import io.github.talelin.latticy.vo.UpdatedVO;
import io.github.talelin.latticy.vo.zty.DispatchDetailVO;
import io.github.talelin.latticy.vo.zty.DispatchListVO;
import io.github.talelin.latticy.vo.zty.OutputDetailVO;
import io.github.talelin.latticy.vo.zty.OutputListVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Positive;
import java.util.List;
@RestController
@RequestMapping("/dispatch")
public class DispatchController {

    @Autowired
    OutputListService outputListService;

    @Autowired
    DispatchListService dispatchListService;

    @GetMapping("/dispatchList")
    @LoginRequired
    public List<DispatchListVO> getOutputList(){
        List<DispatchListVO> dispatchLists = dispatchListService.getDispatchLists();
        return dispatchLists;
    }

    @GetMapping("/details/{id}")
    @LoginRequired
    public List<DispatchDetailVO>  getReplenishApplyDetailById(@PathVariable(value = "id") @Positive(message = "{id.positive}") Integer id){
        System.out.println(id);
        List<DispatchDetailVO> dispatchDetailsByListId = dispatchListService.getDispatchDetailsByListId(id);
        return dispatchDetailsByListId;
    }


    @PutMapping("/confirm/{id}/{handlerId}")
    @LoginRequired
    @Transactional
    public UpdatedVO passReplenishApply(@PathVariable(value = "id") @Positive(message = "{id.positive}") Integer id, @PathVariable(value = "handlerId") @Positive(message = "{handlerId.positive}") Integer handlerId){
        System.out.println(handlerId);
        System.out.println(id);
        DispatchList dispatchList = dispatchListService.getBaseMapper().selectById(id);
        dispatchList.setStatus(4);
        int i = dispatchListService.getBaseMapper().updateById(dispatchList);
        return new UpdatedVO(18);
    }
}
